package com.sgcc.epri.dcloud.controller;

import com.sgcc.epri.dcloud.pojo.Result;
import com.sgcc.epri.dcloud.pojo.TableHead;
import com.sgcc.epri.dcloud.service.TableHeadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tableHead")
@Api(description = "列及列属性操作")
public class TableHeadController {

    @Autowired
    private TableHeadService tableHeadService;

    @GetMapping("/insertOne")
    @ApiOperation("新增一行（在请求此接口时，界面不要刷新）")
    public Result insertOne(@RequestParam(value = "treeId",required = true)@ApiParam(required = true) String treeId,
                            @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType){
        return tableHeadService.insertOne(treeId, dataType);
    }

    @GetMapping("/queryObjects")
    @ApiOperation("查询对象类型（用户选择后直接调用 update 接口）。如何选择了断面的话，则提示考核的断面id范围须在程序的配置文件中配置。")
    public Result queryObjects(@RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType){
        return tableHeadService.queryObjects(dataType);
    }

    @PostMapping("/update")
    @ApiOperation("简单修改调用（一般不刷新页面）| 可修改该表头是否隐藏，hidden_flag字段， 0隐藏、1不隐藏")
    public Result update(@RequestBody TableHead tableHead){
        return tableHeadService.update(tableHead);
    }

    @GetMapping("/queryIndex")
    @ApiOperation("获取指标")
    public Result queryIndex(@RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType){
        return tableHeadService.queryIndex(dataType);
    }

    @GetMapping("/queryCurrentTableIndex")
    @ApiOperation("查询当前表头配置了那些指标")
    public Result queryCurrentTableIndex(@RequestParam(value = "tableHeadId",required = true)@ApiParam(required = true) String tableHeadId){
        return tableHeadService.queryCurrentTableIndex(tableHeadId);
    }

    @GetMapping("/queryAssetByObjectId")
    @ApiOperation("根据对象id查询资产类型（调用此接口前，该条记录的对象必须选好）。 因为数据可能过多，所以需要支持滚动条分页及模糊搜索。")
    public Result queryAssetByObjectId(@RequestParam(value = "objectId",required = true)@ApiParam(required = true) String objectId,
                                       @RequestParam(value = "assetType",required = false)@ApiParam(value = "调用 queryAssetType接口获取 ",required = false) String assetType,
                                       @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType,
                                       @RequestParam(value = "page",required = true)@ApiParam(value = "页数 ", name = "page", required = true) Integer page,
                                       @RequestParam(value = "limit",required = true)@ApiParam(value = "条数 ", name = "limit", required = true) Integer limit,
                                       @RequestParam(value = "key",required = false)@ApiParam(value = "模糊查询", name = "key", required = false) String key){
        return tableHeadService.queryAssetByObjectId(objectId, dataType, page, limit, key, assetType);
    }

    @PostMapping("/updateDifficulty")
    @ApiOperation("修改指标名称或资产类型时调用 string 参数多个id用逗号拼接")
    public Result updateDifficulty(@RequestParam(value = "type",required = true) @ApiParam(value = "列类型 ：101:指标名称，102:资产类型", name = "type", required = true) String type,
                                   @RequestParam(value = "tableHeadId",required = true)@ApiParam(value = "表头id", name = "tableHeadId", required = true) String tableHeadId,
                                   @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType,
                                   @RequestParam(value = "indexId",required = false)@ApiParam(value = "指标id", name = "indexId", required = false) String indexId,
                                   @RequestBody String string){
        return tableHeadService.updateDifficulty(type, tableHeadId, string, dataType, indexId);
    }

    @GetMapping("copyIndexParam")
    @ApiOperation("复制当前表头下的其他指标参数")
    public Result copyIndexParam(@RequestParam(value = "type",required = true) @ApiParam(value = "列类型 ：101:指标名称，102:资产类型", name = "type", required = true) String type,
                                 @RequestParam(value = "tableHeadId",required = true)@ApiParam(value = "表头id", name = "tableHeadId", required = true) String tableHeadId,
                                 @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType,
                                 @RequestParam(value = "indexIdMe",required = false)@ApiParam(value = "指标id", name = "indexIdMe", required = false) String indexIdMe,
                                 @RequestParam(value = "indexIdHim",required = false)@ApiParam(value = "指标id", name = "indexIdHim", required = false) String indexIdHim){
        return tableHeadService.copyIndexParam(type, tableHeadId, dataType, indexIdMe, indexIdHim);
    }
    @GetMapping("/upOrDown")
    @ApiOperation("上移或下移")
    public Result upOrDown(@RequestParam(value = "hostId",required = true) @ApiParam(value = "主id 初始位置", name = "hostId", required = true) String hostId,
                           @RequestParam(value = "rmId",required = true) @ApiParam(value = "次id 目标位置", name = "rmId", required = true) String rmId){
        return tableHeadService.upOrDown(hostId, rmId);
    }

    @GetMapping("/deleteTableHead")
    @ApiOperation("删除表头")
    public Result deleteTableHead(@RequestParam(value = "tableHeadId",required = true) @ApiParam(value = "表头id", name = "tableHeadId", required = true) String tableHeadId){
        tableHeadService.deleteTableHead(tableHeadId);
        return Result.success("删除成功");
    }

    @GetMapping("/queryTableHead")
    @ApiOperation("根据树形结构id和dataType（dky or nr）两个条件来查询")
    public Result queryTableHead(@RequestParam(value = "treeId",required = true)@ApiParam(value = "树形结构id ", name = "treeId", required = true) String treeId,
                                 @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType,
                                 @RequestParam(value = "page",required = true)@ApiParam(value = "页数 ", name = "page", required = true) Integer page,
                                 @RequestParam(value = "limit",required = true)@ApiParam(value = "条数 ", name = "limit", required = true) Integer limit){
        return tableHeadService.queryTableHead(treeId, dataType, page, limit);
    }

    @GetMapping("/queryParamContent")
    @ApiOperation("查询表头配置详情")
    public Result queryParamContent(@RequestParam(value = "tableHeadId",required = true)@ApiParam(value = "表头id ", name = "tableHeadId", required = true) String tableHeadId,
                                    @RequestParam(value = "type",required = true) @ApiParam(value = "列类型 ：101:指标名称，102:资产类型", name = "type", required = true) String type,
                                    @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType,
                                    @RequestParam(value = "indexId",required = false)@ApiParam(value = "指标id", name = "indexId", required = false) String indexId,
                                    @RequestParam(value = "objectId",required = false)@ApiParam(value = "配置南瑞调用时，需传objectId", name = "objectId", required = false) String objectId)
    {
        return tableHeadService.queryParamContent(tableHeadId, type, dataType, indexId, objectId);
    }

    @GetMapping("/conventionalConfiguration")
    @ApiOperation("沿用配置。如果在调用接口前已经有数据了，那么要提示【继续操作会清除当前配置】。此接口在执行过程中可能要较长时间，因此调用后，要在界面上展示【正在复制中...请稍后】")
    public Result conventionalConfiguration(@RequestParam(value = "currentTreeId",required = true)@ApiParam(value = "树id", name = "currentTreeId", required = true) String currentTreeId,
                                         @RequestParam(value = "targetTreeId",required = true) @ApiParam(value = "被复制树id", name = "targetTreeId", required = true) String targetTreeId,
                                            @RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType
                                            ){
        return tableHeadService.conventionalConfiguration(currentTreeId, targetTreeId, dataType);
    }

    @GetMapping("queryAssetType")
    @ApiOperation("获取资产类型")
    public Result queryAssetType(@RequestParam(value = "dataType",required = true)@ApiParam(value = "哪一方的数据？dky or nr ", name = "dataType", required = true) String dataType){
        return tableHeadService.queryAssetType(dataType);
    }
}
